package ${packageName}.entity;

import com.swak.App;
<#if isUseMerge>
import com.swak.annotation.Column;
</#if>
import com.swak.annotation.Table;
import com.swak.persistence.Model;
import com.swak.persistence.BaseMapper;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * ${className}.
 * 
 * @author Auto Generator
 * @date ${date}
 */
@Getter
@Setter
@Accessors(chain = true)
@Table(value="${table.name}"<#if isUseMerge>, useMerge = true</#if>)
public class ${className} extends Model<${className}, ${pk}> {
	
	@lombok.EqualsAndHashCode.Exclude
	@lombok.ToString.Exclude
	private static volatile transient BaseMapper<${className}, ${pk}> _mapper;
	
	<#-- 生成静态属性 -->
	<#list table.columns as c>
	public static final String ${c.javaField?cap_first} = "${c.name}";
	</#list>
	
	<#-- 生成字段属性 -->
	<#list table.columns as c>
	<#-- 如果不是基类属性 -->
	<#if !c.isBaseEntity && !c.isIdEntity && !(isUseMerge && c.isMergAbleColumn)>
	private ${c.javaType} ${c.javaField};
	<#elseif !c.isBaseEntity && !c.isIdEntity>
	@Column(stat = true)
	private ${c.javaType} ${c.javaField};
	</#if>
	</#list>
	
	<#-- 自动生成主键 -->
	<#if !isLongPk>
	@Override
	public String prePersist() {
		return this.initDates();
	}
	</#if>
	
	@Override
	@SuppressWarnings("unchecked")
	protected BaseMapper<${className}, ${pk}> getSqlRunner() {
		if (_mapper == null) {
			synchronized (${className}.class) {
				if (_mapper == null) {
					_mapper = (BaseMapper<${className}, ${pk}>) App.getBean(getTableDefine().getMapper());
				}
			}
		}
		return _mapper;
	}
	
	public static ${className} of() {
	    return new ${className}();
	}
}